<template>
  <div class="loginform">
    <h2>欢迎来到好客来电商平台</h2>
    <el-form :label-position="'right'" label-width="120px" :model="form" :rules="rules" ref="lmform">
      <el-form-item label="用户名" prop="loginName">
        <el-input placeholder="请输入用户名或邮箱或手机号" v-model="form.loginName"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input placeholder="请输入密码" v-model="form.password" show-password></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login()">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "LoginForm",
  data () {
    return {
      form: {
        loginName: '',
        password: ''
      },
      rules: {
        loginName: [
          { required: 'true', message: '用户名不能为空', trigger: 'blur'}
        ],
        password: [
          { required: 'true', message: '密码不能为空', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    login() {
      this.$axios.post('/ums-user/login', this.form, responese => {
        this.$store.commit('SET_TOKEN',responese.obj.token)
        this.$store.commit('SET_MENU',responese.obj.menu)
        this.$router.push('/index')
      },this.$refs['lmform'])
    }
  }
}
</script>
<style lang="less" scoped>
  .loginform {
    padding-top: 30px;
    box-sizing: border-box;
    h2 {
      text-align: center;
    }
    .el-form {
      padding-top: 30px;
      padding-right: 100px;
    }
  }
</style>